package compostie.pattern.demo;

import java.util.List;

/**
 * Created by 逸足天涯 on 10/19/2019.
 */
public class CompositePatternEx {
    public static void main(String[] args) {
        Teacher principal = new Teacher("Dr.S.Som", "Principal");
        Teacher hodMaths = new Teacher("Mrs.S.Das", "Hod-Math");
        Teacher hodCompSc = new Teacher("Mr.V.Sarcar", "Hop-ComputerSc.");

        Teacher mathsTeacher1 = new Teacher("Math Teacher-1", "MathsTeacher");
        Teacher mathsTeacher2 = new Teacher("Math Teacher-1", "MathsTeacher");

        Teacher cseTeacher1 = new Teacher("CSE Teacher-1", "CSETeacher");
        Teacher cseTeacher2 = new Teacher("CSE Teacher-2", "CSETeacher");
        Teacher cseTeacher3 = new Teacher("CSE Teacher-3", "CSETeacher");

        //Principal is on the top of collage
        /*HOD - Maths and Comp.Sc directly reports to him*/
        principal.add(hodMaths);
        principal.add(hodCompSc);

        /*Teacher of Mathematice directly reports to HOd-Maths*/
        hodMaths.add(mathsTeacher1);
        hodMaths.add(mathsTeacher2);

        /*Teacher of Computer of Sc.directly rports to HOD-Comp.SC*/
        hodCompSc.add(cseTeacher1);
        hodCompSc.add(cseTeacher2);
        hodCompSc.add(cseTeacher3);

        /*Leaf nodes. There is no department under Mathematics*/
        mathsTeacher1.add(null);
        mathsTeacher2.add(null);

        /*Leaf nodes. There is no department under CSE*/
        cseTeacher1.add(null);
        cseTeacher2.add(null);
        cseTeacher3.add(null);

        //Printing the details
        System.out.println("***Compsite Pattern Demo***");
        System.out.println("\nThe Collage has following structure\n");
        System.out.println(principal.getDetails());
        List<ITeacher> hods = principal.getControllingDepts();
        for (int i = 0; i <hods.size() ; i++) {
            System.out.println("\t" + hods.get(i).getDetails());
        }

        List<ITeacher> mathTeachers = hodMaths.getControllingDepts();
        for (int i = 0; i < mathTeachers.size(); i++) {
            System.out.println("\t\t" + mathTeachers.get(i).getDetails());
        }

        List<ITeacher> cseTeachers = hodCompSc.getControllingDepts();
        for (int i = 0; i <cseTeachers.size() ; i++) {
            System.out.println("\t\t " + cseTeachers.get(i).getDetails());
        }

        //one Computer teacher leaving
        hodCompSc.remove(cseTeacher2);

        System.out.println("After CSE Teacher-2 leaving the organization -CSE" +
                "depatment has following  employees");
        cseTeachers = hodCompSc.getControllingDepts();
        for (int i = 0; i <cseTeachers.size() ; i++) {
            System.out.println("\t\t " + cseTeachers.get(i).getDetails());
        }


    }
}
